home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
weapons
/
Dynamite.lua
< prev
next >
Wrap
Text File
|
2010-09-28
|
6KB
|
160 lines
--------------------------------------------------------------------------------
-- Weapon Dynamite + Projectile Dynamite
-- Original Carnage Contest Weapon
-- Script by DC, August 2009, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.dynamite={}
cc.dynamite.dynamite={}
-- Load & Prepare Ressources
cc.dynamite.gfx_wpn=loadgfx("weapons/dynamite.bmp") -- Weapon Image
setmidhandle(cc.dynamite.gfx_wpn)
cc.dynamite.sfx_attack=loadsfx("throw.ogg") -- Attack Sound
cc.dynamite.sfx_bounce=loadsfx("bounce.wav") -- Bounce Sound
cc.dynamite.sfx_fuse=loadsfx("fuse.wav") -- Fuse Sound
--------------------------------------------------------------------------------
-- Weapon: dynamite
--------------------------------------------------------------------------------
cc.dynamite.id=addweapon("cc.dynamite","Dynamite",cc.dynamite.gfx_wpn,1) -- Add Weapon (1 use)
function cc.dynamite.draw() -- Draw
if getplayeraction(0)==0 and weapon_shots<=0 then
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
setrotation(0)
drawimage(cc.dynamite.gfx_wpn,getplayerx(0)+getplayerdirection(0)*7,getplayery(0)+2)
end
end
function cc.dynamite.attack(attack) -- Attack
if (weapon_shots<=0) then
if attack==1 then
-- No more weapon switching!
useweapon(0)
playsound(cc.dynamite.sfx_attack)
weapon_shots=weapon_shots+1
id=createprojectile(cc.dynamite.dynamite.id)
projectiles[id]={}
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+getplayerdirection(0)*7
projectiles[id].y=getplayery(0)+2
-- Set speed of projectile
projectiles[id].sx=getplayerdirection(0)*1.2 --getplayerdirection(0)*2
projectiles[id].sy=-1
-- Set timer
projectiles[id].timer=3*50
-- End Turn
endturn()
end
end
end
--------------------------------------------------------------------------------
-- Projectile: dynamite
--------------------------------------------------------------------------------
cc.dynamite.dynamite.id=addprojectile("cc.dynamite.dynamite") -- Add Projectile
function cc.dynamite.dynamite.draw(id) -- Draw
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
setrotation(0)
-- Fuse Sound
if channelplaying(0)==0 then playsound(cc.dynamite.sfx_fuse,0) end
-- Draw projectile
drawimage(cc.dynamite.gfx_wpn,projectiles[id].x,projectiles[id].y)
-- Draw Arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.dynamite.dynamite.update(id) -- Update
-- Fire Particle
local f=getframe()
if f%4==0 then
particle(p_smoke,projectiles[id].x,projectiles[id].y-5)
particlespeed(math.random(-2,2)*0.1,math.random(-6,-3)*0.1)
particlefadealpha(0.01)
particle(p_spark,projectiles[id].x,projectiles[id].y-5)
end
if f%6==0 then
particle(p_lightpuff,projectiles[id].x,projectiles[id].y-5)
particlespeed(math.random(-2,2)*0.1,math.random(-5,-2)*0.1)
particlefadealpha(0.04)
end
-- Gravity influence on speed + decrease x speed
projectiles[id].sx=projectiles[id].sx*0.95
projectiles[id].sy=projectiles[id].sy+getgravity()
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
-- Move X
projectiles[id].x=projectiles[id].x+msubx
if collision(cc.dynamite.gfx_wpn,projectiles[id].x,projectiles[id].y)==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
if (math.abs(projectiles[id].sx)>0.5) then playsound(cc.dynamite.sfx_bounce) end
projectiles[id].x=projectiles[id].x-msubx
projectiles[id].sx=-projectiles[id].sx*0.05
msubx=-msubx*0.05
end
else
projectiles[id].ignore=0
end
-- Move Y
projectiles[id].y=projectiles[id].y+msuby
if collision(cc.dynamite.gfx_wpn,projectiles[id].x,projectiles[id].y)==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
if (math.abs(projectiles[id].sy)>0.5) then playsound(cc.dynamite.sfx_bounce) end
projectiles[id].y=projectiles[id].y-msuby
projectiles[id].sy=-projectiles[id].sy*0.3
msuby=-msuby*0.3
end
else
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
playsound(sfx_hitwater1)
stopchannel(0)
-- Free projectile
freeprojectile(id)
break
end
end
-- Timer -> Explode
projectiles[id].timer=projectiles[id].timer-1
if projectiles[id].timer<=0 then
-- Cause damage
arealdamage(projectiles[id].x,projectiles[id].y,125,65)
-- Destroy terrain
terrainexplosion(projectiles[id].x,projectiles[id].y,55,1)
-- Crater
grey=math.random(0,40)
if math.random(0,1)==1 then
terrainalphaimage(gfx_crater150,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
else
terrainalphaimage(gfx_crater175,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
end
stopchannel(0)
-- Free projectile
freeprojectile(id)
end
-- Scroll to projectile
scroll(projectiles[id].x,projectiles[id].y)
end